package com.work.rcj.config;

import com.work.rcj.common.exception.BusinessException;
import com.work.rcj.common.exception.ErrorEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 简单的登录拦截器
 */
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler) {
        String token = request.getHeader(("token"));
        if (StringUtils.isEmpty(token)) {
            throw new BusinessException(ErrorEnum.MUST_LOGIN);
        }
        return true;
    }


}